using System;

namespace LimitatorInterfaces.CorrectServices
{
    public class SimpleLimitCorrector : ILimitCorrector
    {
        public bool Correct(LimitEntity sourceLimit, CorrectionLimitEntity correction)
        {
            decimal val = sourceLimit.Value;

            switch (correction.CorrectionType)
            {
                case CorrectionType.Add:
                    val += correction.Value;
                    break;

                case CorrectionType.Clear:
                    val = 0;
                    break;

                case CorrectionType.Percent:
                    val = Math.Round(val + (val * correction.Value / 100), 2);
                    break;

                case CorrectionType.Replace:
                    val = correction.Value;
                    break;
            }

            sourceLimit.SetValue(val);
            correction.SetApplied();
            return true;
        }
    }
}